package com.reserveme.servlet;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.*;
import javax.servlet.http.*;

import com.reserveme.*;

@SuppressWarnings("serial")
public class QueryServlet extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		QueryWrapper wrapper = new QueryWrapper();
		try {
			SimpleDateFormat datef = new SimpleDateFormat();
			datef.applyPattern("yyyy/M/d");
			Date date = datef.parse(request.getParameter("dateParam"));
			List<Resource> results = wrapper.query(date,"");
			
			request.setAttribute("result", (List<Resource>)results);
			request.setAttribute("query", 1);
			request.setAttribute("date", date.toString());
			System.out.println(results.size());
			
			RequestDispatcher view = request.getRequestDispatcher("query.jsp");
			view.forward(request, response);
		} catch(Exception e) {
			System.out.println(e.getMessage() + "\n" + "BUGGGGGG");
		}
	}
}
